from django.db import models

CATEGORY_CHOICES = [
    (0, "Python"),
    (1, "HTML"),
    (2, "CSS"),
    (3, "Java"),
    (4, "Node.js"),
    (5, "爬虫"),
]


class Learn(models.Model):
    title = models.CharField(max_length=100, verbose_name="标题", blank=False)
    description = models.CharField(max_length=100, blank=True, null=True, verbose_name="描述")
    url = models.CharField(max_length=100, blank=True, null=True, verbose_name="链接地址")
    logo = models.ImageField(upload_to='LearnLogo/', null=True, blank=True, verbose_name='logo')
    category = models.SmallIntegerField(choices=CATEGORY_CHOICES, default=1, verbose_name="分类")
    created_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
    updated_time = models.DateTimeField(auto_now=True, verbose_name='更新时间')

    def __str__(self):
        return self.title

    class Meta:
        db_table = 'learn'
        verbose_name = '学习资源'
        verbose_name_plural = verbose_name
